package com.ellwood.copyright.common.core.utils;

import cn.hutool.crypto.symmetric.AES;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.common.core.utils
 * @ClassName: EllAESUtil
 * @Description: // 加密解密工具类
 * @Author: Ellwood
 * @CreateDate: 2024/11/23 - 14:30
 * @Version: V1.0.0
 */
public class EllAESUtil {

    // 自定义密钥（必须为16字节）
    private static final String KEY="1234567890abcdef";
    private static final AES AES_INSTANCE  = new AES(KEY.getBytes(EllCharsetUtil.CHARSET_UTF_8));

    /**
     * 加密字符串
     * @param plainText 明文
     * @return 加密后的密文（Base64 编码）
     */
    public static String encrypt(String plainText) {
        byte[] encryptedData = AES_INSTANCE.encrypt(plainText);
        return Base64CustomUtil.encodeWithoutPadding(encryptedData);
    }

    /**
     * 解密字符串
     * @param encryptedText 加密后的密文
     * @return 解密后的明文
     */
    public static String decrypt(String encryptedText) {
        byte[] encryptedData = Base64CustomUtil.decodeWithoutPadding(encryptedText);
        return AES_INSTANCE.decryptStr(encryptedData,EllCharsetUtil.CHARSET_UTF_8);
    }


}
